package com.fcat.common.user.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fcat.springboot.mybatis.util.JsonUtil;
import com.fcat.base.common.util.StrUtil;
import com.fcat.common.user.entity.User;
import org.springframework.stereotype.Service;
import com.fcat.springboot.mybatis.service.impl.TsuantoneBaseServiceImpl;
import com.fcat.common.user.mapper.CompanyMapper;
import com.fcat.common.user.entity.Company;

import com.fcat.common.user.service.CompanyService;

import java.util.Date;

@Service
public class CompanyServiceImpl extends TsuantoneBaseServiceImpl<CompanyMapper,Company> implements CompanyService{

    @Override
    public JSONObject addCompany(Company company) {
        if (company == null) return JsonUtil.getFailJsonObject("请填写完整单位信息");
        if (StrUtil.isBlank(company.getName())) return JsonUtil.getFailJsonObject("请填写完整单位全称");
        if (StrUtil.isBlank(company.getTaxpayerIdentificationNumber())) return JsonUtil.getFailJsonObject("请填写完整纳税人识别号");
        if (StrUtil.isBlank(company.getUnitAddr())) return JsonUtil.getFailJsonObject("请填写单位注册地址");
        if (StrUtil.isBlank(company.getUnitCategory())) return JsonUtil.getFailJsonObject("请填写单位类别");
        if (StrUtil.isBlank(company.getTechnicalDirector())) return JsonUtil.getFailJsonObject("请填写技术负责");
        if(company.getTechnicalStaffTotal()==null) return JsonUtil.getFailJsonObject("请填写技术人员总数");
        Date now = new Date();
        company.setCreateTime(now);
        company.setUpdateTime(now);
        Integer num = super.insert(company);
        if (num == 1) {
            JSONObject result = new JSONObject();
            result.put("id", company.getId());
            return JsonUtil.getSuccessJsonObject(result);
        }
        return JsonUtil.getFailJsonObject("注册失败");
    }
}